public class Solution {
    public static int minSubArrayLen(int target, int[] nums) {
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        if (sum < target) {
            return 0;
        }
        sum = 0;
        int min = nums.length;
        int i = 0;
        int result = 0;
        for (int j = 0; j < nums.length; j++) {
            sum += nums[j];
            while (sum >= target) {
                result = j - i + 1;
                min = minR(result,min);
                sum -= nums[i++];
            }
        }
        return min;
    }
    public static int minR(int i, int j) {
        if (i < j) {
            return i;
        } else {
            return j;
        }
    }

    public static void main(String[] args) {
        int[] nums = {2,3,1,2,4,3};
        int ret = minSubArrayLen(7,nums);
        System.out.println(ret);
    }
}